import numpy as np
from initialize_fdtd_material_grid import TN1,n_1,n_2,n_3
from define_problem_space_parameters import boundary,dx,dy,dz,src_pos_x,src_pos_y,src_pos_z,src_compoinent
from  calculate_domain_size import fdtd_domain,nx,ny,nz
from get_node_indices import get_node_indices1
import environment_pool as env
# defining output parameters
print("defining output parameters")
sampled_electric_fields = []
sampled_magnetic_fields = []
sampled_voltages = []
sampled_currents = []
ports = [] #计算远场时参数
farfield = {"frequencies": np.array([])}

# figure refresh rate
plotting_step = 100

# mode of operation
run_simulation = True
show_material_mesh = True
show_problem_space = True

# far field calculation parameters
farfield["frequencies"] = [1.0e9]
farfield["number_of_cells_from_outer_boundary"] = 13

# frequency domain parameters
frequency_domain = {"start": env.frequency_domain_pool["start"],"end": env.frequency_domain_pool["end"],"step": env.frequency_domain_pool["step"]}
node_coordinates_xe = np.arange(nx+1)*dx + fdtd_domain["min_x"]
node_coordinates_ye = np.arange(ny+1)*dy + fdtd_domain["min_y"]
node_coordinates_ze = np.arange(nz+1)*dz + fdtd_domain["min_z"]
# define sampled electric fields (字典列表实现结构体数组)
sampled_electric_fields = [
    {"x": src_pos_x,"y": src_pos_y,"z": src_pos_z,"component": src_compoinent,"display_plot": False},  # 激励源位置
    {"x": 108e-3 + 30e-3,"y": 0,"z": 0,"component": "z","display_plot": False},
    {"x": 108e-3 + 20e-3,"y": 0,"z": 0,"component": "z","display_plot": False},
]
node_indices = get_node_indices1(sampled_electric_fields[0], node_coordinates_xe,node_coordinates_ye,node_coordinates_ze)
source = {"x":node_indices["is"]-1,"y":node_indices["js"]-1,"z":node_indices["ks"]-1}
ind_start = 3
ind_think = boundary["cpml_number_of_cells_xn"] + 4

ind_is = np.arange(TN1,TN1+n_1)
ind_js = np.arange(TN1,TN1+n_2)
ind_ks = np.arange(TN1+5,TN1+n_3+5)
for ind_i in ind_is:
    for ind_j in ind_js:
        for ind_k in ind_ks:
            sampled_electric_field = {
                "x":(ind_i+1) * dx + fdtd_domain["min_x"], "y":(ind_j+1) * dy + fdtd_domain["min_y"],
                "z":(ind_k+1) * dz + fdtd_domain["min_z"],"component":'m',"display_plot":False}
            sampled_electric_fields.append(sampled_electric_field)
# define animation (嵌套字典实现结构体)
animation = [
    {
        "field_type": "e","component": "m","plane_cut": [
        {"type": "zx","position": 0}
        ],
        "display_grid": False,"display_objects": True,"save_movie": True,"view_angles": [15, 15],"zoom": 0.8,"enable": False}
]
